<?php
/**
 * Created by PhpStorm.
 * User: phc
 * Date: 19-8-16
 * Time: 下午1:07
 */

namespace app\admin\controller;


use app\common\model\AboutModel;
use think\Controller;

class AboutController extends Controller
{
    public function job()
    {
        return view();
    }

    public function jobPage()
    {
        if ($this->request->isAjax()) {
            $post = $this->request->post();
            $item = new AboutModel();
            $data = $item->getJobsPage($post['limit'], $post['page']);
            $count = $item->getJobsCount();
            return pagejson($data, $count);
        }
    }

    public function jobAdd()
    {
        if (!$this->request->isAjax()) {
            $data['item'] = null;
            return view('jobform', $data);
        }
        $post = $this->request->post();
        $result = false;
        if ($post) {
            $post["conditions"] = $post["content"];
            unset($post["content"]);
            $aboutModel = new AboutModel();
            $result = $aboutModel->addJob($post);
        }
        if ($result === false) {
            return zbcjson(false, '插入错误', 101);
        } else {
            return zbcjson(true);
        }
    }

    public function jobEdit($id = 0)
    {
        $aboutModel = new AboutModel();
        if (!$this->request->isAjax()) {
            $data['item'] =$aboutModel->getJobById($id);
            return view('jobform', $data);
        }
        $post = $this->request->post();
        $post["conditions"] = $post["content"];
        unset($post["content"]);
        $result = $aboutModel->updateJobById($post);
        if ($result === false) {
            return zbcjson(false, '修改错误', 101);
        } else
            return zbcjson(true);
    }

    public function jobDelete()
    {
        $post = $this->request->post();
        $result = false;
        $data = $post['data'];
        $item = new AboutModel();
        $result = $item->deleteJobs($data);
        if ($result === false) {
            return zbcjson(false, '删除错误', 101);
        } else
            return zbcjson(true);

    }
}